/*
*  通用状态管理
*/
import API from '@/api';
const SET_SETTING_INFO = 'SET_SETTING_INFO'; // 事例动作常量
const SET_ACCOUNT_INFO = 'SET_ACCOUNT_INFO'; // 事例动作常量
const SET_MOBILE_VALUE = 'SET_MOBILE_VALUE'; // 事例动作常量
const state = {
  settingInfo: {},
  accountInfo: {},
  mobileValue: ''
};
const getters = {
  settingInfo: state => state.settingInfo,
  accountInfo: state => state.accountInfo,
  mobileValue: state => state.mobileValue
};
const actions = {
  setSettingInfo({ commit }) {
    API.global.settingInfo().then((res) => {
      commit(SET_SETTING_INFO, res.data);
    });
  },
  setMobileValue({ commit }) {
    API.user.getUserInfo().then(res => {
      commit(SET_MOBILE_VALUE, res.data.mobile);
    });
  },
  setAccountInfo({ commit }, data) {
    API.user.accountInfo().then(res => {
      commit(SET_ACCOUNT_INFO, res.data);
    });
  }
};

const mutations = {
  [SET_SETTING_INFO](state, data) {
    state.settingInfo = data;
  },
  [SET_MOBILE_VALUE](state, data) {
    state.mobileValue = data;
  },
  [SET_ACCOUNT_INFO](state, data) {
    state.accountInfo = data;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
